<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2 id="tarName">修改密码</h2>
    </header>
</div>
<div class="header-h" style="padding-top: 1.5rem;"></div>
<section class="html_section pr30 pl30 pt20 pb40 login_section">
    <div class="f26">
        <div class="line_center" id="old"><input class="login_input" id="old_pwd" placeholder="请输入原密码" type="password"/>
        </div>
        <div class="line_center"><input class="login_input" id="new_pwd" placeholder="请输入新密码（建议使用字母数字组合）" type="password"/></div>
        <div class="line_center"><input class="login_input" id="new_pwd2" placeholder="再次输入新密码" type="password"/></div>
    </div>
    <div tapmode class="btn1 mt100 f30" onclick="setPassword()" id="submit">确认修改</div>
</section>
<section class="mask_pop">
    <div class="mask" style="display: block"></div>
    <div class="msg_pop">
        <div class="msg_pop_title">提示</div>
        <div class="msg_pop_content">修改密码成功</div>
        <div class="btn3" onclick="popClose();">知道了</div>
    </div>
</section>
</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
    var pwdType = '';
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()

        getMemberInfo()
    };


    //修改密码  设置密码
    function setPassword() {
        if (pwdType == 1) {
            var param = {
                token: $api.getStorage('token'),
                type: pwdType,//类型：1设置密码 2修改密码
                password: $("#new_pwd").val(),
            }
            if (!isDefine(param.password) || !isDefine($('#new_pwd2').val())) {
                pop.notice('请输入新密码', 2);
                return;
            }
            if (param.password != $('#new_pwd2').val()) {
                pop.notice('两次密码不一致', 2);
                return;
            }
        } else {
            var param = {
                token: $api.getStorage('token'),
                type: pwdType,//类型：1设置密码 2修改密码
                password: $("#old_pwd").val(),
                new_password: $("#new_pwd").val(),
            }
            if (!isDefine(param.new_password) || !isDefine($('#new_pwd2').val())) {
                pop.notice('请输入新密码', 2);
                return;
            }
            if (param.new_password != $('#new_pwd2').val().toString()) {
                pop.notice('两次密码不一致', 2);
                return;
            }
        }

        pop.loading();
        getAjax(Interface.edit_password, param, function (res) {
            console.log(JSON.stringify(res));
            popOpen();
            // pop.notice(res.msg);
            pop.close();
        },function (error) {

            pop.notice(error.msg);
            pop.close();
        })
    }

    //获取用户信息
    function getMemberInfo() {
        var type = $api.getStorage('userInfo').password;
        if (type == 0) {
            pwdType = 1;
            $("#tarName").html('设置密码');
            $("#old").hide();
            $("#submit").html('确认密码');
            $(".msg_pop_content").html('设置密码成功');
        } else {
            pwdType = 2;
        }
    }


    function popOpen() {
        $(".mask").show();
        $(".mask_pop").addClass("on");
    }

    function popClose() {
        $(".mask").hide();
        $(".mask_pop").removeClass("on");
        comeBack();
    }
</script>
